@extends('admin.layout.homeindex')
@section('content')
<!--//////////////////////////////////////////////////-->
<!--///////////////////  个人中心页  ///////////////////-->
<!--//////////////////////////////////////////////////-->
<!--导入插件-->
	<script type="text/javascript" src="/HO/ssxjs/jquery.js"></script>
	<script type="text/javascript" src="/HO/ssxjs/area.js"></script>
	<script type="text/javascript" src="/HO/ssxjs/location.js"></script>
<div id="page-content" class="single-page">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<ol class="breadcrumb">
				  <li><a href="{{url('/homeuser/homeuser')}}">个人中心</a></li>
				  <li><a href="{{url('/homeuser/homeuserdata')}}">个人资料</a></li>
				  <li><a href="{{url('/homeuser/homeuserpass')}}">修改密码</a></li>
				  <li><a href="{{url('/homeuser/homeuseraddress')}}">地址管理</a></li>
				  <li><a href="">我的收藏</a></li>
				  <li><a href="{{url('/cart/index')}}">购物车</a></li>
				  <li><a href="#">我的订单</a></li>
				</ol>
			</div>
		</div>
		<!-- 收货地址 -->
		<div class="row">
			<div class="col-lg-12">
				<div class="heading"><h5>地址管理</h5></div>
				@if(session('success'))
				<div class="col-md-6 col-md-offset-3">
					<div class="alert alert-info alert-dismissable">
		            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
						{{session('success')}}
		        	</div>
		    	</div>
				@endif
				@if(session('error'))
                <div class="alert alert-danger alert-dismissable col-md-6 col-md-offset-3">
                    <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                    {{session('error')}}
                </div>
            	@endif
			</div>

		<div class="table-responsive">
	        <table class="table">
	            <thead>
	                <tr>
	                    <th>收货人</th>
	                    <th>电话</th>
	                    <th>地址</th>
	                    <th>操作</th>
	                </tr>
	            </thead>
	            <tbody>
	            @foreach($address as $k=>$v)
	                <tr>
	                    <td>{{$v->uname}}</td>
	                    <td>{{$v->phone}}</td>
	                    <td>{{$v->ssx}}{{$v->jiedao}}</td>
	                    <td>
	                    	<a href="/homeuser/addressdelete?id={{$v->id}}" class="fa fa-times">删除</a>&nbsp;&nbsp;<b>|</b>&nbsp;&nbsp;
	                    	<a href="/homeuser/addressedit?id={{$v->id}}" class="glyphicon glyphicon-pencil">修改</a>
	                    </td>
	                </tr>
	            @endforeach 
	            </tbody>
	        </table>
	    </div>
     	<!-- Button trigger modal -->
		<button class="btn btn-primary btn btn-1" data-toggle="modal" data-target="#myModal">
		  添加收货地址
		</button>
		<!-- 收货人信息 -->
	    <div class="col-lg-12">
	        <h5 class="page-header">
			<!-- 添加收货地址摸态框 -->
			<!-- Modal -->
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			  <div class="modal-dialog">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h4 class="modal-title" id="myModalLabel">新的收货地址</h4>
			      </div>
			      <form action="/homeuser/insert" method="post" id="ff1" name="form1" class="address">
				      <div class="modal-body">
			      			<div class="form-group">
			      				<input type="text" required="" id="" name="uname" placeholder="收货人姓名 :" class="form-control">
			      			</div>
			      			<div class="form-group">
			      				<input type="text" required="" id="" name="phone" placeholder="收货人电话 :" class="form-control">
			      			</div>
			      				<!--层级联动选择框-->
								<select id="loc_province" class="" name="sheng" style="width:80px;font-size:15px;"></select>
								<select id="loc_city" class="" name="shi" style="width:100px;font-size:15px;"></select>
								<select id="loc_town" class="" name="xian" style="width:120px;font-size:15px;"></select>
			      			<div class="form-group">
			      				<input type="text" required="" id="" name="jiedao" placeholder="街道地址 :" class="form-control">
			      			</div>
				      </div>
				      <div class="modal-footer">
				      	<input type="hidden" name="ssx" value="">
				      	{{csrf_field()}}
				        <button type="reset" class="btn btn-default" data-dismiss="modal">重置</button>
				        <button class="btn btn-primary">添加</button>
				      </div>
			      </form>
			    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
			</div><!-- /.modal -->
	        </h5>
	    </div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		showLocation();
		$('#addresses .attr').each(function(){
			var str = $(this).attr('attr');
			var info = getInfo(str);
			$(this).html(info);
		});

		//定义获取城市信息方法
		function getInfo(str){
			//console.log(str);
			//拆分字符串
			var arr = str.split(',');
			// console.log(arr);	
			var ls  = new Location;
			var l = ls.items;
			// console.log(l['0,1,2']['5']);
			var sheng = l['0'][arr[0]];
			var shi = l['0,'+arr[0]][arr[1]];
			var xian = l['0,'+arr[0]+','+arr[1]][arr[2]];
			return sheng+shi+xian;
		}

		//地址操作 提交表单时获取详细的省市限
		$('.address').submit(function(){
			//获取要提交的省市县编号
			var sheng = $('#loc_province').val();
			var shi = $('#loc_city').val();
			var xian = $('#loc_town').val();
			var str = sheng+','+shi+','+xian;
			var res = getInfo(str);
			$(this).find('input[name=ssx]').val(res);
		});


		//点击选中默认地址
		$('#addresses .item').each(function(){
			$(this).click(function(){
				//
				$('#addresses .item').removeClass('aa');	
				$(this).addClass('aa');
				//获取当前点击的地址id
				var id  = $(this).attr('aid');	
				$('input[name=address_id]').val(id);
			})
		})				
	});
</script>
@endsection('content')
